const app = getApp()
const request = require('../../../utils/https.js')
import util from '../../../utils/util.js';
var fromUser, userId;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 3000,
    duration: 1000,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //检查服务是否暂停
    request._get(getApp().Api_url + 'system', {}, function (res) {
      if (res.data.errMsg == 'OK') {
        var flag = res.data.data.on;
        if (!flag) {
          wx.reLaunch({
            url: '/pages/stop1/stop1'
          })
          return false;
        }
      }
    }, function () { })
    console.log('options===>', options)
    const that = this;
    userId = wx.getStorageSync('userId');
    let fastId = options.urlId;
    that.setData({
      url: options.url,
      urlId: fastId
    })
    if (options.url == 'SVIP') {
      wx.setNavigationBarTitle({
        title: '直升SVIP专区'
      })
      that.fastMain(fastId, userId);
    } else if (options.url == 'VIP') {
      wx.setNavigationBarTitle({
        title: '直升VIP专区'
      })
      that.fastMain(fastId, userId);
    } else if (options.url == 'Brand') {
      wx.setNavigationBarTitle({
        title: '精选品牌'
      })
      that.brand(fastId, userId)
    }else if(options.url == 'holiday'){
      let lt =  options.titles;
      let aid = options.aid;
      if(lt == '' || lt == null || lt == 'undefined'){
        lt = "优惠活动"
      }
      wx.setNavigationBarTitle({
        title: lt
      })
      that.holiday(aid)
    }
  },
  //会员介绍
  lookLevel () {
    const that = this;
    let ImgLinks = 'https://oss.km3830.cn/h5/km_web.html';
    wx.navigateTo({
      url: '/pages/webview/webview?url=' + ImgLinks,
    })
  },
  //VIP-SVIP封装函数
  fastMain (fastId, userId) {
    const that = this;
    //商品列表
    request._get(getApp().Api_url + 'goods/fastMain', { //商品列表接口
      fastId: fastId,
      userId: userId,
      pageNum: 1,
      pageSize: 1000
    }, function (res) {
      if (res.data.errMsg == 'OK') {
        var dataList = res.data.data;
        that.setData({
          dataList: dataList,
          goodsList: dataList.children
        })

      }
    }, function () { })
  },


  //精选品牌
  holiday (aid) {
    const that = this;
    //精选品牌
    request._get(getApp().Api_url + 'goods/holiday', {
       aid: aid,
      userId: userId
    }, function (res) {
      if (res.data.code == '200') {
        var dataList = res.data.data;
        that.setData({
          dataList: dataList,
          goodsList: dataList.prodList
        })
      }

    }, function () { })
  },






  //查看详情页
  goDetails (e) {
    const that = this;

    let userId = wx.getStorageSync("userId");
    if (userId == '' || userId == null || userId == 'undefined') {
      wx.reLaunch({
        url: '/pages/login/login?path=/pages/list/list'
      })
      return;
    }
    let goodsId = e.currentTarget.dataset.goodsid;
    let goodsType = e.currentTarget.dataset.kinds;
    let fast = e.currentTarget.dataset.fast;
    /*     let userId = wx.getStorageSync("userId");
         if (userId == '' || userId == null || userId == 'undefined') {
          wx.navigateTo({
            url: '/pages/login/login',
          })
          return;
        } */
    wx.navigateTo({
      url: '/pages/gift_details/gift_details?goodsId=' + goodsId + '&show=' + 0 + '&userId=' + fromUser + '&fast=' + fast
    })
  },
  //详情页拉起购物车
  goShopping (e) {
    const that = this;
    let userId = wx.getStorageSync("userId");
    if (userId == '' || userId == null || userId == 'undefined') {
      wx.reLaunch({
        url: '/pages/login/login?path=/pages/list/list'
      })
      return;
    }
    let goodsId = e.currentTarget.dataset.goodsid;
    let goodsType = e.currentTarget.dataset.kinds;
    let fast = e.currentTarget.dataset.fast;

    /*     let userId = wx.getStorageSync("userId");
        if (userId == '' || userId == null || userId == 'undefined') {
          wx.navigateTo({
            url: '/pages/login/login',
          })
          return;
        } */

    wx.navigateTo({
      url: '/pages/gift_details/gift_details?goodsId=' + goodsId + '&show=' + 1 + '&userId=' + fromUser + '&fast=' + fast
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  /*   onPullDownRefresh: function () {

    }, */

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  /* onShareAppMessage: function (res) {
    const that = this;
    if (res.from === 'button') {
      return {
        title: '快美甄选',
        path: '/packageA/pages/VIP/VIP?urlId=' + that.data.urlId + '&url=' + that.data.url + '&userId=' + userId
      }
    } else {
      return {
        title: '快美甄选',
        path: '/packageA/pages/VIP/VIP?urlId=' + that.data.urlId + '&url=' + that.data.url + '&userId=' + userId
      }
    }
  } */
})